0% found this document useful (0 votes)
34 views

Arduino

This document contains code snippets for several Arduino projects: 1) Blinking an LED on pin 13 on and off every second. 2) Reading the state of a button on pin 2 and turning an LED on pin 13 on when the button is pressed. 3) Reading the value of a sensor on analog pin A0 and using it to set the on and off times of an LED on pin 13. 4) Mapping sensor values from analog pin 0 to values from 0-255 and storing them in EEPROM addresses 0-511. 5) Printing sensor values from analog pin A0 to the serial monitor every second. 6) Controlling the position of a servo attached to pin 9 based

Uploaded by

hhhangarita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Arduino

This document contains code snippets for several Arduino projects: 1) Blinking an LED on pin 13 on and off every second. 2) Reading the state of a button on pin 2 and turning an LED on pin 13 on when the button is pressed. 3) Reading the value of a sensor on analog pin A0 and using it to set the on and off times of an LED on pin 13. 4) Mapping sensor values from analog pin 0 to values from 0-255 and storing them in EEPROM addresses 0-511. 5) Printing sensor values from analog pin A0 to the serial monitor every second. 6) Controlling the position of a servo attached to pin 9 based

Uploaded by

hhhangarita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

MICROS

ARDUINO
int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW); delay(1000);
}
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
int sensorPin = A0;
int ledPin = 13;
int sensorValue = 1000;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
}
#include <EEPROM.h>
int addr = 0;
void setup()
{
}
void loop()
{
int val = analogRead(0) ;
val=map(val, 0, 1023, 0,255);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == 512)
addr = 0;
delay(100);
}
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1);}
#include <Servo.h>
Servo servo1;
int potpin = 0;
int val;
void setup()
{
servo1.attach(9);
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
servo1.write(val);
delay(15);
}
const int analogInPin = A0;
const int analogOutPin = 9;
int sensorValue = 0;
int outputValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(analogOutPin, outputValue);
Serial.print("sensor = " );
Serial.println(sensorValue);
Serial.print("output = ");
Serial.println(outputValue);
delay(2); //outputValue=Serial.read();
}

You might also like