One ultrasonic sensor (MB7380) is operating with TTL. I want to send the same signal that this sensor would output, as a sweep. In other words, please help with writing code for sweeping from where the sensor would read 0 to near the maximum range (roughly 5-meters).
I've taken an introductory EE logic course; so either understanding this wasn't covered or I'm over-complicating it. A datalogger board will be reading the 9600 baud TTL signal. (That is how I will be confirming it sends the desired signals.)
More specifically, the sensor uses the signal pins 4 and 5. The datasheet above has details.
How was this sensor connected to the datalogger? Someone else, out-of-house, did that before me. I have their contact info if I should need to ask certain questions. (I Googled and tried finding a solution myself, but no progress.)

/*
Test rig -- output ~ simulates sensors -- to Q4 datalogger
*/
#include<LiquidCrystal.h>
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000;
int pinAnalog = 2;
int pinDigital = 3;
int pinOneWire = 4;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Arduino pins. Creates object
// LCD pin (RS enable D4 D5 D6 D7) parameters
void setup() {
Serial.begin(9600);
lcd.begin(20, 4);
startMillis = millis(); //initial start time
// pinMode not needed for OUTPUT operator
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
pinMode(14, INPUT);
pinMode(15, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
}
void loop() {
currentMillis = millis(); // milliseconds since start
lcd.setCursor(0, 0);
lcd.print("Welcome.");
lcd.setCursor(0, 1);
lcd.print("Ready to make a selection.");
analogSelection = digitalRead(pinAnalog); // 2
digitalSelection = digitalRead(pinDigital); // 3
oneWireSelection = digitalRead(pinOneWire); // 4
if(analogSelection == HIGH)
{
currentMillisA = millis();
if(currentMillisA - startMillis > 1000*60) // one min.
{
lcd.clear();
lcd.setCursor(0, 0); // 1st line
lcd.print("Testing...");
lcd.setCursor(0, 1); // 2nd
lcd.print("Analog inputs");
lcd.setCursor(0, 2); // 3rd
lcd.print("Please wait 4 min.");
for(int pin = 0; pin < 8; pin++)
for(int s = 63; s <= 255; s += 64)
{ // PWM: 255 = 5V
analogWrite(pin, s); // sweeps 1.24, 2.5, 3.75 & 5V
startMillis = currentMillis; //IMPORTANT to save start time of current state
}
}
}
else if(digitalSelection == HIGH)
{
// DO - User toggled switch to simulate the ultrasonic sensor.
}
else if(oneWireSelection == HIGH)
{
currentMillis1 = millis();
if(currentMillis1 - startMillis > 1000*60) // one min.
{
// TODO
startMillis = currentMillis1; //IMPORTANT to save start time of current state
}
}
else
// error message for multiple inputs at once
}
This is what I have so far. Note, none of it so far is for the digital TTL GPIO. (I think I created a simple voltage sweep for the analog pins of the datalogger board. Corrections and related comments are welcome =) If it matters, I'm using the Mega2560.