EasyManua.ls Logo

Seeed Grove Beginner Kit - Page 32

Seeed Grove Beginner Kit
71 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Software Code
Open Arduino IDE.
Copy the following code, click Verify to check for syntax errors. Verify that there are no
errors, and you can upload the code.
// Light Switch
int sensorpin = A6; // Analog input pin that the sensor is attached to
int ledPin = 4; // LED port
int sensorValue = 0; // value read from the port
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(sensorpin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
Serial.println(sensorValue);
// change the analog out value:
analogWrite(ledPin, outputValue);
delay(30);
}
You can also see the light intensity readings from the Serial Monitor, navigate to Tools -> Serial
Monitor.
31
Grove Beginner Kit For Arduino®

Other manuals for Seeed Grove Beginner Kit

Related product manuals