donderdag 14 april 2011

Robotje poging 0.1

Benodigdheden:
1 robotplatform met 2 wielen en 2 motortjes (voorbeeld)
1 arduino uno (voorbeeld)
1 motorshield voor arduino uno (voorbeeld)
2 ir sensors (voorbeeld)

Het robotje in elkaar vijzen is eenvoudig. Om de motortjes aan te sluiten heb je wat soldeer nodig.
Het robotje is nog niet perfect. Objecten schuins vooraan worden opgemerkt en ontweken, maar wat recht voor de robot is worden niet gezien en dus niet ontweken.

de sketch:
int l_sensorPin = 0; // select the input pin for the sensor
int r_sensorPin = 1; // select the input pin for the sensor
int l_ledPin = 11; // select the pin for the LED
int r_ledPin = 10; // select the pin for the LED
int l_sensorValue = 0; // variable to store the value coming from the sensor
int r_sensorValue = 0; // variable to store the value coming from the sensor

int E1 = 4; // select the pin for the E1
int E2 = 7; // select the pin for the E2
int M1 = 5; // select the pin for the M1
int M2 = 6; // select the pin for the M2

void setup() {
pinMode(E1, OUTPUT);
pinMode(E2, OUTPUT);
}

void loop() {
// read the value from the sensor:
digitalWrite(E1,HIGH);
digitalWrite(E2,HIGH);
l_sensorValue = analogRead(l_sensorPin);
r_sensorValue = analogRead(r_sensorPin);

l_sensorValue = map(l_sensorValue,0,512,255,0);
r_sensorValue = map(r_sensorValue,0,512,255,0);

analogWrite(M1,l_sensorValue);
analogWrite(l_ledPin,l_sensorValue);
analogWrite(M2,r_sensorValue);
analogWrite(r_ledPin,r_sensorValue);
}




Geen opmerkingen:

Een reactie posten