I’m having an issue getting the HC-SR04 Ultrasonic sensor functioning on an ATtiny2313a-PU.
Background:
I was trying to build this:
The core I’m using: - the board I select is ATtiny2313 @ 1MHz
The ultrasonic library: - I also tried NewPing, but am having trouble getting it going.
I have identified the issue to be the ultrasonic sensor not functioning when connected to the ATtiny. The sensor, when connected to the Arduino Uno, works fine - when you bring your ear close to the sensor you can hear the ‘pings’ (clicking sound) happening at a very rapid rate.
However, when connected to the ATtiny, you can only hear a ping about once every second. i.e. the ATtiny is not operating the sensor and therefore not measuring the range. From the code below, only the LED on pin 7 remains on.
I have tested the ATtiny’s pins, all of which function correctly when lighting LEDs in a set frequency and duration. I have also tried getting this going with three separate sensors, three separate ATtinys, and 20 different pin combinations, but no luck.
It would be great if any of you had any ideas as to how I could get this working. Thanks in advance.
#include <Ultrasonic.h> int Echo=11; int Trig=10; int Range; int Dist; Ultrasonic ultrasonic(Trig,Echo); void setup () { pinMode(9, OUTPUT); pinMode(7, OUTPUT); Dist=15; } void loop() { Range = ultrasonic.Ranging(CM); // Range is calculated in Inches. if (Range > Dist){ digitalWrite(9, HIGH); digitalWrite(7, LOW); } else{ digitalWrite(9, LOW); digitalWrite(7, HIGH); } delay(20); }