top of page
Search

Arduino Programming

  • Writer: raghuramansanjana
    raghuramansanjana
  • Nov 10, 2022
  • 1 min read

Updated: Dec 17, 2022

In this page I will describe:

There are 4 tasks that will be explained in this page:

  1. Input devices:

  2. Interface a potentiometer analog input to maker UNO board and measure/show its signal in serial monitor Arduino IDE.

  3. Interface a LDR to maker UNO board and measure/show its signal in serial monitor Arduino IDE

  4. Output devices:

  5. Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc)​

  6. Include the pushbutton on the MakerUno board to start/stop part 2.a. above

For each of the tasks, I will describe:

  1. The program/code that I have used and explanation of the code. The code is in writable format (not an image).

  2. The sources/references that I used to write the code/program.

  3. The problems I encountered and how I fixed them.

  4. The evidence that the code/program worked in the form of video of the executed program/code.



code

explanation

int sensorPin = A0;

int ledPin = 13;

int sensorValue = 0;

void setup()

{

pinMode(ledPin,OUTPUT);

}

void loop()

{

sensorValue = analogRead(sensorPin);

digitalWrite(ledPin, HIGH);

delay(sensorValue);

digitalWrite(ledPin, LOW);

delay(sensorValue);

}

​Inside void setup, the pinmode function is used to establish A0 as an input and digital pin 13 as an output. Pin 13 is reflected as LED_BUILTIN on the code.

  • The code inside void loop uses a new function called analogRead to listen to the pin’s state.

  • Comment lines (which helps to clarify what the programme is doing) are marked with double slashes, those are not really included in the final programme.

  • digitalwrite will help to turn the LED on or off depending on whether it is set on high or low.

  • delay function instead of pausing for a fixed amount of time, the value passed to the delay() function will change as the knob of the potentiometer is turned because each time through the loop it’s going to read the position again.


 
 
 

Recent Posts

See All
DOE

In this page i will describe:

 
 
 

Comments


bottom of page