HUUB'S WEBSITE

ARDUINO

X hide video.
X hide video.
X hide video.
X hide video.

description

The Buggy is a Car that during the 
ride can detect a obstacle.
When this happens it stops, go's back
and random go's to the right or the
left. The Buggy is controlled by 2 
ATtiny85 IC's.
                    

sketch

//ATtiny 1 Buggy controlled by 2 
//ATtiny's and 1 motorcontroler L293D
const byte M1vooruitPin = 3;
const byte M1terugPin = 4;
const byte M2vooruitPin = 0;
const byte M2terugPin = 1;
const int readPin = 2;

// buggy forward
void vooruit() {
digitalWrite(M1vooruitPin, HIGH);
digitalWrite(M1terugPin, LOW);
digitalWrite(M2vooruitPin, HIGH);
digitalWrite(M2terugPin, LOW);
}

// buggy back
void achteruit() {
digitalWrite(M1vooruitPin, LOW);
digitalWrite(M1terugPin, HIGH);
digitalWrite(M2vooruitPin, LOW);
digitalWrite(M2terugPin, HIGH);
}

// buggy to the right
void rechtsaf() {
digitalWrite(M1vooruitPin, LOW);
digitalWrite(M1terugPin, HIGH);
digitalWrite(M2vooruitPin, HIGH);
digitalWrite(M2terugPin, LOW);
}

// buggy to the left
void linksaf() {
digitalWrite(M1vooruitPin, HIGH);
digitalWrite(M1terugPin, LOW);
digitalWrite(M2vooruitPin, LOW);
digitalWrite(M2terugPin, HIGH);
}

// buggy stop
void stopBuggy() {
digitalWrite(M1vooruitPin, LOW);
digitalWrite(M1terugPin, LOW);
digitalWrite(M2vooruitPin, LOW);
digitalWrite(M2terugPin, LOW);
}

void setup() {
// Initialise pins
pinMode(M1vooruitPin, OUTPUT);
pinMode(M1terugPin, OUTPUT);
pinMode(M2vooruitPin, OUTPUT);
pinMode(M2terugPin, OUTPUT);
pinMode(readPin, INPUT);
digitalWrite(readPin, LOW);
}

void loop() {
//check distance to obstacle
vooruit();
int sign = digitalRead(readPin);
delay(100);
int S = random(2);
if (sign == HIGH && S == 0){
stopBuggy();
delay(500);
achteruit();
delay(1000);
stopBuggy();
delay(500);
linksaf();
delay(1000);
sign = LOW;
stopBuggy();
delay(500);
}
if (sign == HIGH && S == 1){
stopBuggy();
delay(500);
achteruit();
delay(1000);
stopBuggy();
delay(500);
rechtsaf();
delay(1000);
sign = LOW;
stopBuggy();
delay(500);
}
}

//ATtiny 2 measure distance
#define trigPin 1
#define echoPin 0
#define signaalPin 3

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(signaalPin, INPUT);
}

void loop() {
//controle afstand
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 25 && distance < 200
    && distance > 0  ){
    digitalWrite(signaalPin, HIGH);
}
else{
digitalWrite(signaalPin, LOW);
}
}
                    

parts

ATtiny85                      2x
L293D                         1x
Motor 3-6V with a gearbox     2x
Wheels attatched to motors    2x
Castor wheel front            1x
170 point breadboard          2x
led white                     2x
resistor 220 Ohm              2x
capacitor  22uF               1x
HC-SR04 ultrasonic module     1x
battery holder 4x 1,5V AA     1x
batteries 1,5V AA             4x
switch on/off                 1x
                    

pin-layout

buggy-pin

description

LCD 2x16 controlled by an ATTiny85 
true a shiftregister. 
Of the 5 pins of the ATTiny 
2 are still available. 
With those two pins a servo motor
is controlled.
                    

sketch

//servo libary works with ATtiny85 
#include <SoftwareServo.h>

#include <ShiftLCD.h>
// initialize the library with the 
//numbers of the interface pins 
    ATtiny
ShiftLCD lcd(0, 2, 1);

SoftwareServo myservo;
int pos = 0;
int potPin = A3;
    
void setup() {
// set up the LCD's number of rows  
//and columns: 
    lcd.begin(16, 2);
// Print a message to the LCD.
    lcd.print("Servo position");
    delay(1000);
//set interupt for refreshing the 
    servo
    OCR0A = 0xAF;            
//any number is OK (found this at 
    Adafruit)
    TIMSK |= _BV(OCIE0A);    
//Turn on the compare interrupt 
(below!)
//setup servo
    myservo.attach(PB4);
    myservo.setMaximumPulse(2400);
    myservo.write(pos);
    }
    
void loop() {
    int val;
    val = analogRead(potPin);
    pos = map(val, 0,1023,0,179);
    myservo.write(pos);
    delay(15);
    lcd.setCursor(0,1);
    lcd.print("    ");
    lcd.setCursor(0,1);
    lcd.print(pos);
    delay(500);
    
}

volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
// this gets called every 
    2 milliseconds
    counter += 2;
// every 20 milliseconds, 
    refresh the servos!
    if (counter >= 20) {
    counter = 0;
    SoftwareServo::refresh();
    }
}
                    

parts

ATtiny85                 1x
LCD 2x16 HD44780 comp.   1x
Shiftregister SN74HC595N 1x
Micro Servomotor S90     1x
Potentiometer 10K        2x
Voltage regulator LM7805 1x
Capacitor   0,33uF       1x
Capacitor   0,1 uF       1x
9 volt battery           1x
Wires and connectors
                    

pin-layout

lcd-pin

description

The lego car is remote controlled.
It is powered by a legomotor via 
a L293D H-bridge. 
The whole is controlled by a 
Arduino NANO.
                    

sketch

/*Car with remote controle L293D ,servo 
and joystick*/

#include "RH_ASK.h"

//reciever
RH_ASK driver(2000, 2, 3 , 10);

uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
String str = "";

//Motor
#define motorPin1 5 // Pin  7 op L293
#define motorPin2 4 // Pin  2 op L293
#define motorpwPin 6 // Pin 1 op L293 
//speedcontrole

//servo
int servoPin = 9;
int minPulse = 500;// Linksaf
int maxPulse = 2400;// Rechtsaf
int midPulse = 1450;//Rechtdoor
int pulse = 0;// Amount to pulse the 
servo
int refreshTime = 30000;// the time 
needed in between pulses

int motorSpeed = 225; //default 
motorspeed

//distance measuring
#define trigPin 8
#define echoPin 12

const int speaker = 11;
const int ledrPin = 7;

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

//setup servo motor
pinMode(servoPin, OUTPUT);
    
//Set motor pins as outputs
pinMode(motorPin1, OUTPUT); 
    //aandrijfmotor
pinMode(motorPin2, OUTPUT);
pinMode(motorpwPin, OUTPUT);

//setup reciever
if (!driver.init())
Serial.println("init failed");

//Constrain the new speed of motors 
to be between the range 0-255
constrain(motorSpeed, 0, 255);
analogWrite(motorpwPin, 
    motorSpeed);

//measuring distance
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(speaker, OUTPUT);
pinMode(ledrPin, OUTPUT);
}

void loop(){

//checking afstand
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
//Serial.print(distance);
//Serial.println(" cm");
if (distance > 25 && distance 
< 200 && distance > 0  ){
Stop();
digitalWrite(ledrPin, HIGH);
for (int t = 1; t <= 4; t++){
for (int s = 200; s <> 500; 
    s +=10){
tone(speaker, s, 50);
delay(20);
}
}
Achteruit();
delay(1500);
Stop();
digitalWrite(ledrPin, LOW);
}

//recieving data from sender and joystick
if (driver.recv(buf, &buflen)) 
// Non-blocking
{
int i = 0;
str = "";
for (int i = 0; i < buflen; i++){
str +=(char)buf[i];
}
Serial.println(str);
}
if (str == "VU"){
    Vooruit();
    delay(500);
}
if (str == "AU"){
    Achteruit();
    delay(500);
}
if (str == "RA"){
    RechtsAf();
    delay(500);
}
if (str == "LA"){
    LinksAf();
    delay(500);
}
if (str == "ST"){
    Stop();
    delay(500);
}
}


void  Vooruit(){
analogWrite(motorpwPin, 
    motorSpeed);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
return;
}

void Stop(){
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
return;
} 

void Achteruit(){
analogWrite(motorpwPin, 
    motorSpeed);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
return; 
}

void  RechtsAf(){
Run(maxPulse);
return;
} 

void  LinksAf(){
Run(minPulse);
return;
}

//servomotor
void Run(int pos)
{
digitalWrite(servoPin, HIGH);
//Turn the motor on
delayMicroseconds(pos);
//Length of the pulse sets the 
position
digitalWrite(servoPin, LOW);
//Turn the motor off
delayMicroseconds(refreshTime);
}
----------------------------------
//remote controle joystick en 
RF433MHZ sender
#include "boarddefs.h"
#include "IRremote.h"
#include "IRremoteInt.h"
#include 
"ir_Lego_PF_BitStreamEncoder.h"

#define SW 2
#define Xas A1
#define Yas A0

int x, y;
int switchState = LOW; 

IRsend irsend;

void setup() {
Serial.begin(9600);
pinMode(SW, INPUT);
}


void loop() {
x = analogRead(Xas);
y = analogRead(Yas);
switchState = digitalRead(SW);
Serial.print("x as = ");
Serial.println(x);
Serial.print("y as = ");
Serial.println(y);
Serial.println(switchState);
delay(100);

if (y >= 700){
zend_code(0x5EB92);
//vooruit
}
else if (y <= 300){
zend_code(0x9EB92);
//achteruit
}
else if (x >= 700){
zend_code(0xDEB92);
//rechtsaf
}
else if (x <= 300){
zend_code(0x3EB92);
//linksaf
}
else if (x >= 300 && x le 700 && 
y ge 300 && y <= 700){
zend_code(0xD0B92);
//stop
}

void zend_code(unsigned long Bcode){
//for (int t = 1; t <= 3; t++){
irsend.sendSony(Bcode, 26);
//}
Serial.println(Bcode);
Bcode = 0;
delay(100);
}
                    

parts

parts car:
------------------------------
9 volt batteries       2 st.
L293D motorcontrol     1 st.
Switch on/off          1 st.
Loudspeaker            1 st.
RF433MHZ reciever      1 st.
Lego motor             1 st.
Sonar sensor HC SR04   1 st.
Arduino NANO           1 st.
Funduino breakoutboard 1 st.
Led green              2 st.
Led red                1 st.
Resistor  220 Ohm      3 st.
Techn. Lego severall parts.
Wires.

parts remote controle:
-----------------------------
Arduino NANO           1 st.
Joystick module        1 st.
Push button            1 st.
RF433MHZ sender        1 st.
Powersupply  5 volt    1 st.
                    

pin-layout

lego-pin

description

Controlling devices with an old
dial telephone.
Determing the dialled number by
setting power on a connection
and measuring the fluctuation in 
the power when dialling.
                    

sketch

/*Controlling devices with an old
dial telephone*/
	
#define telPin A0
#define powerPin 3
#define ledPin 5
#define fanPin 4

long startTime;
long duration;
long startDial;
long durDial;
int teller=0;
long lees;

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(fanPin, OUTPUT);
digitalWrite(powerPin, HIGH);
}

void loop() {
  teller=0;
  durDial=0;
  lees = analogRead(telPin);
  delay(3);
  while (lees < 1000){
    startTime=millis();
    while (lees>600){
      duration=millis()-startTime;
      startDial=millis();
      lees = analogRead(telPin);
      delay(3);
    }
    if (duration!=0){
      teller=teller+1;
      Serial.println(teller);
    }
    else if(duration==0 && teller!=0){
      durDial=millis()-startDial;
    }
    duration=0;
    if (durDial>500 && teller>=1){
      Serial.print("gekozen : ");
      Serial.println(teller);
      actie();
      break;
    }
    lees = analogRead(telPin);
    delay(3);
    }
}

void actie(){
  if (teller==1){
    digitalWrite(ledPin, HIGH);
  }
  if (teller==2){
    digitalWrite(fanPin, HIGH);
  }
  
  if (teller==10){
    digitalWrite(ledPin, LOW);
    digitalWrite(fanPin, LOW);
  }
}
                    

parts

parts telephone:
------------------------------
Led blue                  1 st.
Resistor 220 Ohm          1 st.
1 channel relaisboard 5V  1 st.
Contra connector 220V     1 st.
old dial telephone        1 st.
Wires.
                    

pin-layout

lego-pin