I am planning to let an ATTiny85 to:
- Send a message to an Arduino Uno by 315MHz module and
VirtualWire - Send a pulse to SR04
- If receive a pulse, then send a message to the Arduino Uno.
Code for ATTiny85:
#include <VirtualWire.h>
#define TRIG 2
#define MSG 4
#define ECHO A3
void setup() {
// put your setup code here, to run once:
vw_setup(1000);
pinMode(ECHO,INPUT);
pinMode(MSG,OUTPUT);
pinMode(TRIG,OUTPUT);
vw_set_tx_pin(MSG);
}
void loop() {
// put your main code here, to run repeatedly:
send("T1");
digitalWrite(TRIG,LOW);
delay(1000);
digitalWrite(TRIG,HIGH);
delay(200);
digitalWrite(TRIG,LOW);
if (digitalRead(ECHO) == HIGH)
{
send("0");
}
delay(10000);
}
void send (char *message)
{
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx(); // Wait until the whole message is gone
}
But the Attiny isn't sending 0, just "T1". Where could be the problem?