Digital output

// The objective is to switch on and off a led connected in pin 3, when I press 1 or 0 in the arduino console const int outPin = 3 ; void setup () { //settings / figuration file pinMode(outPin, OUTPUT) ; // built-in function. pinMode is a defined function, the first argument is the pin, and the second only can be INPUT or OUTPUT. Serial.begin(9600) ; // Serial is a class and also is the principal class of a library that is included on the core of arduino. The dought sintax indicates a method, Serial.begin indicates serial parameters (Class.method / object.method). A method is a set of functions and a functions is a set of instrucions. Serial has accepts at least four methods (begin, avaliable, read, printl, print, etc...) Serial.println("Enter 1 or 0") ; } // When the text is between "", the languaje does not read that text, so it does not count as functions or variables. void loop() { if (Serial.avaliable() > 0) { char ch=Serial.read() ; // If the value is bigger than 0, we save that value as a character in ch if (ch == "1") { digitalWrite(outPin, HIGH) ; } else if (ch == "0" ) { digitalWrite(outPin,LOW); } }}

Digital input

const int inputPin = 5 ; void setup() { pinMode(intputPin, INPUT) ; Serial.begin(9600) ; { void loop () { int reading = digitalRead(inputPin) ; Serial.println(reading) ; delay(1000); }

Analog output


cost int outPin = 3 
void setup() {
  pinMode(outPin, OUTPUT);
  Serial.begin(9600) ; 
  Serial.println("Enter volts 0-5 ") ; 
void loop(){
  if (Serial.avaliable > 0 ) {
  float volts = Serial.parseFloat*() ; 
  int pwmValue = volts * 255.0/5.0 ; 
  analogWrite(outPin,pwmValue); }}

Analog Input


const int analogPin = A0 ; 
void setup() {
  Serial.begin(9600) ; }
void loop() {
  int reading = analogRead(analogPin);
  float volage = reading / 204.6 ; 
  Serial.print("Reading= ");
  Serial.print(reading);
  Serial.print("\t\tVolt= ");
  Seria.println(voltage);
  delay(500);
  }