Vanemate ringitund 17.05.17

ARDUINO

Ultrasonic sensor

Kauguse mõõtmine Ultrasonic sensoriga. Vahemik on 2 – 400 cm.

http://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/

Tulemus on näha monitooringu aknas.

#define trigPin 13
#define echoPin 12
#define led 11
#define led2 10

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
}

void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);  // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); – Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 4) {  // This is where the LED On/Off happens
digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off
digitalWrite(led2,LOW);
}
else {
digitalWrite(led,LOW);
digitalWrite(led2,HIGH);
}
if (distance >= 200 || distance <= 0){
Serial.println(“Out of range”);
}
else {
Serial.print(distance);
Serial.println(” cm”);
}
delay(500);
}

Vanemate ringitund 03.05.17

ARDUINO

2 x 2 x 2 LED kuup
http://www.instructables.com/id/2x2x2-RGB-Cube-Arduino/

Tegime algust 2x2x2 RGB led kuubi valmistamisega. Tänu sellele sai väga hästi jootmist harjutada.

Dallase termomeetri kasutamine
http://www.instructables.com/id/How-to-use-DS18B20-Temperature-Sensor-Arduino-Tuto/

Selleks oli vaja alla laadida kaks teeki.
https://github.com/milesburton/Arduino-Temperature-Control-Library
https://github.com/PaulStoffregen/OneWire

Kõigepealt mõõtsime toatemperatuuri.

Ja seejärel akna vahelt õue temperatuuri.

 

LÕPMATU PEEGEL

http://www.instructables.com/id/Infinity-Mirror-Table-the-easy-version/

 

Poed, kust on võimalik saada erinevaid elektroonika ja robootika vahendeid:

https://www.oomipood.ee
https://www.noortehnik.ee

Koolivaheaja ringitund 19.04.17

SCRATCH

Pliiatsiga joonistamine

Siin on programm, kus on võimalik ise pliiatsiga värve valida ja erineva laiusega jooni tõmmata.

Taust koos spraitidega näeb selline välja. Taust on lihtsalt valge, aga võib valida endale sobiva.

Iga värvi jaoks tuleb erinev sprait teha. Aga mitte ühe spraidi alla erinevaid kostüümid.

Scratchi pliiats

MOSS

Keerlemas

Vanemate ringitund 05.04.17

ARDUINO ROBOTAUTO

Ultrasonic sensor car

Meie uus robotauto hakkab valmima.

Robotauto ehitamine

http://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/

https://blog.miguelgrinberg.com/post/building-an-arduino-robot-part-i-hardware-components

Joone jälgimine

https://diyhacking.com/make-line-follower-robot/

http://www.circuitstoday.com/line-follower-robot-using-arduino

Takistuste vältimine

http://robotshop.com/letsmakerobots/obstacle-avoidance-robot-car-arduino

http://www.webondevices.com/arduino-robot-car-obstacle-avoidance

http://forum.arduino.cc/index.php?topic=165987.0

http://communityofrobots.com/tutorial/kawal/how-make-your-first-robot-using-arduino

 

Kood, kuidas robotauto juba eelnevalt programmeeritud suundades liigub.

// Motor A pins (enableA = enable motor, pinA1 = forward, pinA2 = backward)
int enableA = 5; //11;
int pinA1 = 8; // 6;
int pinA2 = 7; //5;

//Motor B pins (enabledB = enable motor, pinB2 = forward, pinB2 = backward)
int enableB = 10;
int pinB1 = 4; //4;
int pinB2 = 2; //3;

//This lets you run the loop a single time for testing
boolean run = true;

void setup() {
pinMode(enableA, OUTPUT);
pinMode(pinA1, OUTPUT);
pinMode(pinA2, OUTPUT);

pinMode(enableB, OUTPUT);
pinMode(pinB1, OUTPUT);
pinMode(pinB2, OUTPUT);
}

void loop() {
delay(5000);

if (run) {
delay(2000);
enableMotors();
//Go forward
forward(1000);
//Go backward
backward(1000);
//Turn left
turnLeft(2000);
coast(200);
//Turn right
turnRight(2000);
coast(200);
//This stops the loop
run = false;
}
}

//Define high-level H-bridge commands
void enableMotors()
{
motorAOn();
motorBOn();
}

void disableMotors()
{
motorAOff();
motorBOff();
}

void forward(int time)
{
motorAForward();
motorBForward();
delay(time);
}

void backward(int time)
{
motorABackward();
motorBBackward();
delay(time);
}

void turnLeft(int time)
{
motorABackward();
motorBForward();
delay(time);
}

void turnRight(int time)
{
motorAForward();
motorBBackward();
delay(time);
}

void coast(int time)
{
motorACoast();
motorBCoast();
delay(time);
}

void brake(int time)
{
motorABrake();
motorBBrake();
delay(time);
}

//Define low-level H-bridge commands

//enable motors
void motorAOn()
{
digitalWrite(enableA, HIGH);
}

void motorBOn()
{
digitalWrite(enableB, HIGH);
}

//disable motors
void motorAOff()
{
digitalWrite(enableB, LOW);
}

void motorBOff()
{
digitalWrite(enableA, LOW);
}

//motor A controls
void motorAForward()
{
digitalWrite(pinA1, HIGH);
digitalWrite(pinA2, LOW);
}

void motorABackward()
{
digitalWrite(pinA1, LOW);
digitalWrite(pinA2, HIGH);
}

//motor B controls
void motorBForward()
{
digitalWrite(pinB1, HIGH);
digitalWrite(pinB2, LOW);
}

void motorBBackward()
{
digitalWrite(pinB1, LOW);
digitalWrite(pinB2, HIGH);
}

//coasting and braking
void motorACoast()
{
digitalWrite(pinA1, LOW);
digitalWrite(pinA2, LOW);
}

void motorABrake()
{
digitalWrite(pinA1, HIGH);
digitalWrite(pinA2, HIGH);
}

void motorBCoast()
{
digitalWrite(pinB1, LOW);
digitalWrite(pinB2, LOW);
}

void motorBBrake()
{
digitalWrite(pinB1, HIGH);
digitalWrite(pinB2, HIGH);
}

Kood, kuidas robotauto kaugusandurit testida

Selleks on vaja allalaadida teek (library), kus on vajalikud protseduurid kirjas. Selleks on NewPing.h.

https://bitbucket.org/teckel12/arduino-new-ping/downloads/

Allalaetud ZIP fail lisada Arduino stuudiosse:
Sketch -> Include Library -> Add .ZIP Library

#include <NewPing.h>

//Tell the Arduino where the sensor is hooked up
NewPing sonar(12, 13);

long inches;

void setup() {
//Activate the serial monitor so you can see the output of the sensor
Serial.begin(9600);
}

void loop() {
delay(50);
//Ping the sensor to determine distance in inches
inches = sonar.ping_in();
//Print the distance in inches to the serial monitor
Serial.print(inches);
Serial.print(” in.”);
Serial.print(“\n”);
}

Kood, kuidas robotauto väldib takistusi ja pöörab siis otsa ümber.

#include <NewPing.h>

//Tell the Arduino where the sensor is hooked up
NewPing sonar(12, 13);

int enableA = 11;
int pinA1 = 6;
int pinA2 = 5;

int enableB = 10;
int pinB1 = 4;
int pinB2 = 3;

long inches;

void setup() {
pinMode(enableA, OUTPUT);
pinMode(pinA1, OUTPUT);
pinMode(pinA2, OUTPUT);

pinMode(enableB, OUTPUT);
pinMode(pinB1, OUTPUT);
pinMode(pinB2, OUTPUT);
}

void loop() {

//Run the motors at slightly less than full power
analogWrite(enableA, 200);
analogWrite(enableB, 200);

//Ping the sensor and determine the distance in inches
inches = sonar.ping_in();

//If the robot detects an obstacle less than four inches away, it will back up, then turn left; if no obstacle is detected, it will go forward
if (inches < 4) {
analogWrite(enableA, 255);
analogWrite(enableB, 255);
backward(600);
coast(200);
turnLeft(600);
coast(200);}
else {
forward(1);

}
}

//Define high-level H-bridge commands
void enableMotors()
{
motorAOn();
motorBOn();
}

void disableMotors()
{
motorAOff();
motorBOff();
}

void forward(int time)
{
motorAForward();
motorBForward();
delay(time);
}

void backward(int time)
{
motorABackward();
motorBBackward();
delay(time);
}

void turnLeft(int time)
{
motorABackward();
motorBForward();
delay(time);
}

void turnRight(int time)
{
motorAForward();
motorBBackward();
delay(time);
}

void coast(int time)
{
motorACoast();
motorBCoast();
delay(time);
}

void brake(int time)
{
motorABrake();
motorBBrake();
delay(time);
}

//Define low-level H-bridge commands

//enable motors
void motorAOn()
{
digitalWrite(enableA, HIGH);
}

void motorBOn()
{
digitalWrite(enableB, HIGH);
}

//disable motors
void motorAOff()
{
digitalWrite(enableB, LOW);
}

void motorBOff()
{
digitalWrite(enableA, LOW);
}

//motor A controls
void motorAForward()
{
digitalWrite(pinA1, HIGH);
digitalWrite(pinA2, LOW);
}

void motorABackward()
{
digitalWrite(pinA1, LOW);
digitalWrite(pinA2, HIGH);
}

//motor B controls
void motorBForward()
{
digitalWrite(pinB1, HIGH);
digitalWrite(pinB2, LOW);
}

void motorBBackward()
{
digitalWrite(pinB1, LOW);
digitalWrite(pinB2, HIGH);
}

//coasting and braking
void motorACoast()
{
digitalWrite(pinA1, LOW);
digitalWrite(pinA2, LOW);
}

void motorABrake()
{
digitalWrite(pinA1, HIGH);
digitalWrite(pinA2, HIGH);
}

void motorBCoast()
{
digitalWrite(pinB1, LOW);
digitalWrite(pinB2, LOW);
}

void motorBBrake()
{
digitalWrite(pinB1, HIGH);
digitalWrite(pinB2, HIGH);
}

 

Vanemate ringitund 29.03.17

LITTLE ROBOT FRIENDS

Robotsõbra erinevat värvi silmad

Kuidas panna robotsõbral silmad erinevat värvi põlema. Värvide vahetuse ajal kasutada viiteks “delay” käsku (1000 tähendab 1 sek).

#include <LittleRobotFriends.h> //import LRF library

void setup() {
// turn things on/off before we set-up
lrf.motion.disable();
lrf.hearing.disable();
lrf.touch.disable();
lrf.sight.disable();

lrf.setup(); //setup LRF library
}
void loop() {
lrf.loop(); //service LRF loop

lrf.eyes.set(0, 0, 250); //set LRF LEDs to full brightness
delay(500);
lrf.eyes.set(0, 250, 0); //set LRF LEDs to full brightness
delay(500);
lrf.eyes.set(250, 0, 0); //set LRF LEDs to full brightness
delay(500);
lrf.eyes.setColor(LRFColor_Clear); //clear LRF LEDs (turn off)
delay(500);
lrf.eyes.setLeft(250, 0, 0); //set LRF LEDs to full brightness
delay(500);
lrf.eyes.setRight(250, 0, 0); //set LRF LEDs to full brightness
delay(500);
}

Vanemate ringitund 22.03.17

ARDUINO

LCD ekraani ühendamine:

LCD ekraanil teksti väljastamise kood:

// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// set up a constant for the tilt switchPin
const int switchPin = 6;
// variable to hold the value of the switchPin
int switchState = 0;
// variable to hold previous value of the switchpin
int prevSwitchState = 0;
// a variable to choose which reply from the crystal ball
int reply;
void setup() {
  Serial.begin(9600);
  // set up the number of columns and rows on the LCD
  lcd.begin(16, 2);
}
void loop() {
  lcd.clear();
  lcd.setCursor(0, 0);
      // print some text
      lcd.print(“Fluffy aka Litulu “);
      // move the cursor to the second line
      lcd.setCursor(0, 1);
    lcd.print(“Richardo-kun”);
    delay(3000);
      lcd.clear();
      lcd.setCursor(0, 0);
      // print some text
      lcd.print(“Taugrom aka”);
      // move the cursor to the second line
      lcd.setCursor(0, 1);
    lcd.print(“Lil tau”);
    delay(3000);
}

 

Codebug muusika ja Arduino koos

Vanemate ringitund 15.03.17

ARDUINO

Allolevatest osadest on võimalik ise auto ehitada ja vajalikud andurid külge panna.

CODEBUG

Ennustamine. Mõtle küsimus ja CodeBug vastab, kas jah, ei või võib olla.

Üks näide tehtud koodist on siin:

Vanemate ringitund 01.03.17

ARDUINO

Arduino programm, kuidas kasutada jadapordi monitori. Selleks tuleb Arduino Stuudios Tööriistade alt valida Jadapordi monitor. Alloleva programmi abil on monitoris näha, kuidas muutuja “i” väärtus muutub iga 1 sekundi järel.

const int greenLEDPin = 9; // LED connected to digital pin 9
const int redLEDPin = 10; // LED connected to digital pin 10
const int blueLEDPin = 11; // LED connected to digital pin 11

int redValue = 0; // punane LED
int greenValue = 0; // roheline LED
int blueValue = 0; // sinine LED

void setup() {
Serial.begin(9600);

pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
}

void loop() {
redValue = 255;
greenValue = 0;
blueValue = 0;

for(int i = 0; i<255; i+=10) {
redValue = i;
greenValue = 0;
blueValue = 255-i;

analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);

Serial.print(“Red: “);
Serial.print(redValue);
Serial.print(” Green: “);
Serial.print(greenValue);
Serial.print(” Blue: “);
Serial.println(blueValue);

delay(1000);
}
}

Arduino LED lamp potentsiomeetriga

Arduino LED lamp fototakistiga

CODE.ORG

Siin on näha, kuidas code.org keskkonnas joonistada. Selleks tuleb ülesannete lehekülje kõige alumisest osast leida Projektide osa ja sealt valida Joonista midagi rakendus. Kõik kirjutatud programmid jäävad projektide juurde alles.

Kood näeb selline välja

Lisaks vaatasime natuke ka Kodu Game Lab keskkonda.